<?php

namespace App\Http\Controllers\Admin;
use App\Models\Personal\Resume;
use App\Models\Personal\ResumeCash;
use App\Models\Common\CollOption;
use Illuminate\Http\Request;
use DB,Style;


class PersonalCashController extends CommonController{
    public function __construct(){
    }

    /**
     * 充值提现记录表
     * @param Request $request
     * @return mixed
     */
    public function resumeCash(Request $request){
        $input   = $request->only('keyword', 'type');
        $keyword = (!empty($request->keyword)) ? trim($request->keyword) : '';
        $type    = (!empty($request->type)) ? trim($request->type) : '';

        $resumeCash = DB::table('resume_cash as t1')
            ->leftJoin('resume as t2', 't1.resume_id', '=', 't2.id')
            ->select(
                't1.*',
                't2.name','t2.birthday','t2.mobile','t2.education'
            )
            ->where(function ($query) use($keyword){
                $query->orWhere('t2.name', 'like', '%'.$keyword.'%')
                ->orWhere('t2.mobile','like','%'.$keyword.'%');
            })
            ->where(function ($query) use($type){
                $query->orWhere('t1.cash_type', 'like', '%'.$type.'%');
            })
            ->where('t1.cash_del', 0)
            ->orderBy('t1.created_at','desc')
            ->paginate(20);

        $collOptionEducation = CollOption::where('sign', 'education')->get();//分类表对应学历

        //最高学历
        foreach($resumeCash as $k=>$v){
            foreach($collOptionEducation as $k1=>$v1){
                if($v->education == $v1->opt_id){
                    $resumeCash[$k]->education_name = $v1->opt_name;
                    continue 2;
                }
            }
        }
        //充值类型
        foreach($resumeCash as $v){
            switch($v->cash_type){
                case 1:
                    $v->cash_type_name = '充值';
                    break;
                case 2:
                    $v->cash_type_name = '提现';
                    break;
            }
        }
        return Style::view('admin.personal_manage.resume_cash',compact('resumeCash'));
    }
  
    /**
     * 删除充值提现
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delCash(Request $request){
        $result = ResumeCash::where('id', $request->id)->update(['cash_del'=>1]);
        if($result){
            return response()->json(['status' => 0,'msg' => '记录删除成功！']);
        }else{
            return response()->json(['status' => 1,'msg' => '记录删除失败，请稍后重试！']);
        }
    }

}

























